﻿/*
 * @author: wizardc
 */

using Dou.UI;
using UnityEditor;
using UnityEngine;

namespace DouEditor.UI
{
    [CustomEditor(typeof(RichText), true)]
    [CanEditMultipleObjects]
    public class RichTextEditor : UnityEditor.UI.TextEditor
    {
        [MenuItem("GameObject/DouUI/RichText", false, 10)]
        private static void CreateUI(MenuCommand menuCommand)
        {
            var go = UIEditorUtil.CreateUIElement("RichText");
            var text = go.AddComponent<RichText>();
            text.text = "New Text";
            text.supportRichText = true;
            text.raycastTarget = false;
            UIEditorUtil.PlaceUIElementRoot(go, menuCommand);
        }
        
        private SerializedProperty _onHrefClick;

        protected override void OnEnable()
        {
            base.OnEnable();
            _onHrefClick = serializedObject.FindProperty("_onHrefClick");
        }

        public override void OnInspectorGUI()
        {
            var text = (RichText) target;
            using (new GUILayout.VerticalScope())
            {
                text.richTextAsset = (RichTextAsset) EditorGUILayout.ObjectField(new GUIContent("富文本资源"), text.richTextAsset, typeof(RichTextAsset));
            }
            base.OnInspectorGUI();
            EditorGUILayout.PropertyField(_onHrefClick);
            serializedObject.ApplyModifiedProperties();
        }
    }
}
